package com.gpj.learn.rabbitmq.springboot.controller;

import com.gpj.learn.rabbitmq.springboot.common.MessageType;
import com.gpj.learn.rabbitmq.springboot.common.MyMessage;
import com.gpj.learn.rabbitmq.springboot.service.RabbitSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.UUID;


/**
 * @className TestController
 * @description
 *   TODO
 * @author GPJ
 * @date 2021/6/8 14:01
 * @version 1.0
 **/
@RestController("/produce")
public class ProduceController {
	@Autowired
	private RabbitSender sender;

	@GetMapping("/work")
	public String work() {
		for (int i = 0; i <10 ; i++) {
			sender.send(MessageType.TEST_WORK,
					new MyMessage(i + ":" + UUID.randomUUID().toString(), new Random().nextInt() + i));
		}
		return "success:" + UUID.randomUUID().toString();
	}

	@GetMapping("/fanout")
	public String fanout(){
		for (int i = 0; i <10 ; i++) {
			sender.send(MessageType.TEST_FANOUT,
					new MyMessage(i + ":" + UUID.randomUUID().toString(), new Random().nextInt() + i));
		}
		return "success:" + UUID.randomUUID().toString();
	}

	@GetMapping("/routing")
	public String routing(){
		for (int i = 0; i <10 ; i++) {
			sender.send(MessageType.TEST_ROUTING,
					new MyMessage(i + ":" + UUID.randomUUID().toString(), new Random().nextInt() + i));
		}
		return "success:" + UUID.randomUUID().toString();
	}

	@GetMapping("/topic")
	public String topic(){
		for (int i = 0; i <10 ; i++) {
			sender.send(MessageType.TEST_TOPIC,
					new MyMessage(i + ":" + UUID.randomUUID().toString(), new Random().nextInt() + i));
		}
		return "success:" + UUID.randomUUID().toString();
	}
}
